﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;

namespace KylinORM.Data
{
    /// <summary>
    /// 数据访问接口的数据库类型
    /// </summary>
    public enum EDataProviderType
    {
        /// <summary>
        /// 连接到SqlServer2005以上版本的数据库
        /// </summary>
        SqlServer,
        /// <summary>
        /// 连接到SqlServerCE4.0以上版本的数据库
        /// </summary>
        SqlServerCe,
        /// <summary>
        /// 连接到MySql数据库
        /// </summary>
        MySql,
        /// <summary>
        /// 暂不支持
        /// </summary>
        Oracle,
        /// <summary>
        /// 暂不支持
        /// </summary>
        SQLite
    }

    /// <summary>
    /// 数据访问类接口
    /// </summary>
    public interface IDataProvider
    {
        /// <summary>
        /// 连接字符串
        /// </summary>
        string ConnectionString { get; }
        /// <summary>
        /// 超时时间
        /// </summary>
        int CommandTimeout { get; }
        /// <summary>
        /// 数据库类型
        /// </summary>
        EDataProviderType ProviderType { get; }
        /// <summary>
        /// 创建数据库连接
        /// </summary>
        /// <returns></returns>
        IDbConnection CreateConnection();
        /// <summary>
        /// 创建数据库命令
        /// </summary>
        /// <param name="query">数据库请求</param>
        /// <returns></returns>
        IDbCommand CreateCommand(DataQuery query);
        /// <summary>
        /// 创建查询参数
        /// </summary>
        /// <param name="name">参数名称</param>
        /// <param name="value">参数值</param>
        /// <returns></returns>
        DbParameter CreateParameter(string name, object value);

        /// <summary>
        /// 执行一条SQL语句，返回一个数据集
        /// </summary>
        /// <param name="query">需要执行的语句</param>
        /// <returns></returns>
        DataRow ExecuteDataRow(DataQuery query);
        /// <summary>
        /// 执行一条SQL语句，返回一个数据表
        /// </summary>
        /// <param name="query">需要执行的语句</param>
        /// <returns></returns>
        DataSet ExecuteDataSet(DataQuery query);
        /// <summary>
        /// 执行一条SQL语句，返回一个数据行
        /// </summary>
        /// <param name="query">需要执行的语句</param>
        /// <returns></returns>
        DataTable ExecuteDataTable(DataQuery query);

        /// <summary>
        /// 执行一条SQL语句，返回第一行第一列的值
        /// </summary>
        /// <param name="query">需要执行的语句</param>
        /// <returns></returns>
        int ExecuteNonQuery(DataQuery query);
        /// <summary>
        /// 执行一条SQL语句，返回语句所影响的行数
        /// </summary>
        /// <param name="query">需要执行的语句</param>
        /// <returns></returns>
        object ExecuteScalar(DataQuery query);
    }
}
